package br.com.estevam.sisfin.daos;

import org.apache.tapestry5.hibernate.HibernateSessionManager;
import org.apache.tapestry5.services.ApplicationStateManager;
import org.hibernate.Criteria;

import br.com.estevam.sisfin.daos.interfaces.BancoDAO;
import br.com.estevam.sisfin.entities.Banco;

public class BancoDAOImpl extends AbstractDAOImpl implements BancoDAO {

	public BancoDAOImpl(HibernateSessionManager hsm, ApplicationStateManager asm){
		super(hsm, asm, Banco.class);
		executarCriarBanco();
	}

	public Banco findByDescricao(String descricao) {
		Criteria c = createCriteria();
		c = addEqRestriction(c, "descricao", descricao);
		return (Banco) c.uniqueResult();
	}
	
	public Banco findByCodBanco(int codBanco) {
		Criteria c = createCriteria();
		c = addEqRestriction(c, "codBanco", codBanco);
		return (Banco) c.uniqueResult();
	}
	
	void executarCriarBanco(){
		if(rowCountAll() == 0){
			add(new Banco(1,"BANCO DO BRASIL"));
			add(new Banco(35,"BANCO DO ESTADO DO CEARÁ"));
			add(new Banco(104,"CAIXA ECONOMICA FEDERAL"));
			add(new Banco(123,"BANCO REAL"));
			add(new Banco(233,"UNIBANCO"));
			add(new Banco(237,"BRADESCO PRIME"));
			add(new Banco(275,"BANCO REAL"));
			add(new Banco(320,"BICBANCO"));
			add(new Banco(341,"ITAÚ"));
			add(new Banco(356,"BANCO REAL S/A"));
			add(new Banco(392,"BANCO MERCANTIL DE SÃO PAULO - FINASA"));
			add(new Banco(399,"HSBC"));
			add(new Banco(409,"UNIBANCO"));
			add(new Banco(479,"BANCO BOSTON"));
			
			commit();
		}
	}

}
